package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.mapper.SysCorpMapper;
import com.dengbw.systemtransfer.model.SysCorpVo;
import com.dengbw.systemtransfer.model.db.SysCorp;
import com.dengbw.systemtransfer.model.db.SysOrg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author dengbw
 * @date 2021/11/12 8:39 上午
 */
@Service
public class QueryService {
    SysCorpMapper sysCorpMapper;

    @Autowired
    public QueryService(SysCorpMapper sysCorpMapper) {
        this.sysCorpMapper = sysCorpMapper;
    }

    public List<SysCorpVo> queryCorp(String name) {
        List<SysCorp> orgs = sysCorpMapper.queryList(v -> v.like("name", name));
        return orgs.stream().map(v -> {
            SysCorpVo vo = new SysCorpVo();
            vo.setName(v.getName());
            vo.setCorpID(v.getDingCorpId());
            vo.setAppKey(v.getDingAccessKey());
            vo.setAppSecret(v.getDingAccessSecret());
            return vo;
        }).collect(Collectors.toList());
    }
}
